package com.ubs.web.client.security;

import java.util.ArrayList;
import java.util.List;

import com.ubs.dom.Account;

public class SecurityContext {

	private static List<SecurityListener> listeners = new ArrayList<SecurityListener>();
	private static Account account;
	
	public static Account getAccount() {
		return account;
	}

	private static void notifyAccountLoggedIn(Account account) {
		for (SecurityListener listener : listeners) {
			listener.onAccountLoggedIn(account);
		}
	}

	private static void notifyAccountLoggedOut() {
		for (SecurityListener listener : listeners) {
			listener.onAccountLoggedOut();
		}
	}
	
	public static void addSecurityListener(SecurityListener listener) {
		listeners.add(listener);
	}

	public static void setAccount(Account account) {
		SecurityContext.account = account;
		if (account != null) {
			notifyAccountLoggedIn(account);
		} else {
			notifyAccountLoggedOut();
		}
	}

}
